#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <inttypes.h>
#include <iso646.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tgmath.h>
#include <time.h>
#include <uchar.h>
#include <wchar.h>
#include <wctype.h>

// LIB FROM ${COMMUNIS_PATH}/Deploy_store/.qa/main_repo_fn/dir_c_/_c_/_lib
#include "lib/lc_0.h"
#include "lib/lc_1.h"
#include "lib/io_1.h"
#include "lib/lib_1.h"
#include "lib/uni_1.h"

#define N 6

#include <sys/stat.h>
#include <sys/types.h>

#include <unistd.h>
#include <fcntl.h>

/* CELEBI03

   This example determines if a file descriptor is
   associated with a terminal.

 */

void check_fd(int fd)
{
    printf("fd %d is ", fd);
    if (!isatty(fd))
        printf("NOT ");
    puts("a tty");
}

int main(int argc, char const *argv[])
{
    int p[2], fd;
    char fn[] = "temp.file";

    if (pipe(p) != 0)
        perror("pipe() error");
    else
    {
        if ((fd = creat(fn, S_IWUSR)) < 0)
            perror("creat() error");
        else
        {
            check_fd(0);
            check_fd(fileno(stderr));
            check_fd(p[1]);
            check_fd(fd);
            close(fd);
            unlink(fn);
        }
        close(p[0]);
        close(p[1]);
    }
    return 0;
}